<script type="text/javascript">
$(document).ready(function(){
	//xóa
	$("#btnDelete").click(function(){
		var valid= false;
		var arrChkId = $(".chkId");
		var strIDs = "";
		for(var i =0; i < arrChkId.length; i++){
			if(arrChkId.eq(i).attr("checked")){
				valid = true;
				if(strIDs!=""){
					strIDs +=","+ arrChkId.eq(i).attr("value");
				}else{
					strIDs +=arrChkId.eq(i).attr("value");
				}
				//break;
			}
		}
		if(valid){
			if(confirm("Bạn thực sự muốn xóa những trang này?")){
				$("#hddIDs").attr("value", strIDs);
				$("#frmActions").attr("action", "<?php echo $this->url(array('type' => $this->type), 'admin_page_delete');?>");
			}else{
				return false;
			}
		}else{
			alert("Xin hãy chọn chuyên mục muốn xóa!");
			return false;
		}
	});
});
</script>
<div id="r-heading">
	<img src="<?php echo PUBLIC_URL.'/admin/images/article.png';?>" alt=""/>
	<span>Danh sách trang</span>
</div>
<?php
//nếu có message thì hiển thị
if(!empty($this->message)){
	echo '<div id="message">'.$this->message.'</div>';
} 
?>
<div>
	<form id="frmActions" action="" method="post">	
		<div id="actions">
			<!--<input type="text" id="txtKeyword" name="keyword" class="text" value="" size="25"/>
			<input type="submit" id="btnSearch" class="button" value="Tìm kiếm"/>  -->
			<input type="button" id="btnCreate" class="button" value="Thêm mới" onclick="location = '<?php echo $this->url(array(), 'admin_page_create');?>';"/>
			<input type="submit" id="btnDelete" class="button" value="Xóa các mục đã chọn"/>
			<input type="hidden" id="hddIDs" value="" name="ids"/>
		</div>
		<table class="list" cellspacing="0">
			<thead>
				<tr>
					<td width="5%">
						<input type="checkbox" class="chkAll"/>
					</td>
					<td width="50%">
						Tiêu đề
					</td>
					<td width="10%">
						Người tạo
					</td>
					<td width="10%">
						Ngày tạo
					</td>
					<td width="15%">
						Chuyên mục
					</td>
					<td width="10%">
						Thao tác
					</td>
				</tr>
			</thead>
			<tbody>
			<?php
			if(count($this->arrPages) == 0){
			?>
				<tr>
					<td colspan="6" style="color: #fc0202;">
						Chưa có trang nào trong cơ sở dữ liệu!
					</td>
				</tr>
			<?php
			}else{
				foreach ($this->arrPages as $page){
			?>
				<tr>
					<td width="5%">
						<input type="checkbox" class="chkId" value = "<?php echo $page->id;?>"/>
					</td>
					<td width="50%">
						<a href="<?php echo  $this->url(array('id' => $page->id),'admin_page_edit');?>"><?php echo $page->title?></a>
						
					</td>
					<td width="10%">
						<?php echo $page->findParentRow('Model_User')->username;?>
					</td>
					<td width="10%">
						<?php echo date('d/m/Y',strtotime($page->created_date));?>
					</td>
					<td width="15%">
						<?php
						echo $page->findParentRow('Model_Category')->name;
						?>
					</td>
					<td width="10%">
						<a href="<?php echo  $this->url(array('id' => $page->id),'admin_page_edit');?>">Sửa</a>
						|
						<a href="<?php echo  $this->url(array('id' => $page->id),'admin_page_delete');?>">Xóa</a>
					</td>
				</tr>
			<?php 
				}
			}?>
			</tbody>
			<tfoot>
				<tr>
					<td width="5%">
						<input type="checkbox" class="chkAll"/>
					</td>
					<td width="50%">
						Tiêu đề
					</td>
					<td width="10%">
						Người tạo
					</td>
					<td width="10%">
						Ngày tạo
					</td>
					<td width="15%">
						Chuyên mục
					</td>
					<td width="10%">
						Thao tác
					</td>
				</tr>
			</tfoot>
		</table>
		<?php
			if(count($this->arrPages) != 0){
				echo $this->paginationControl($this->arrPages,'Sliding','page/pagination.phtml');
			}
			?>
		
	</form>
</div>
